import React, { Component } from 'react'
import './index.css';
export default class index extends Component {
    state = {
        mag:''
    }
    render() {
        return (
            <div className="todo-header">
            <input type="text" placeholder="请输入你的任务名称，按回车键确认" 
            value = {this.state.mag}
            onChange = {this.change}
            onKeyDown = {this.onkeydown}
            />
        </div>
        )
    }
    // 获取元素值
    change = (e)=>{
       this.setState({
           mag:e.target.value
       })
    }
    // 加键盘事件调用夫元素的添加事件
    onkeydown =(e)=>{
        if(e.keyCode === 13){
            this.props.changeDate(this.state.mag);
        }
    }
}
